import util from './util'

/**
 * 用户名密码登录
 * @link http://10.20.5.146:9010/swagger-ui.html
 */
interface Login {
    username: string,
    password: string
}
async function login(params: Login) {
    let login = await util.ajax
        .post(
            '/authorize/login',
            {
                password: params.password,
                username: params.username,
            },
            {
                params: {
                    password: params.password,
                    token_type: 'jwt',
                    username: params.username,
                }
            }
        )
        .then(res => {
            return res.data
        })
        .catch(error => {
            return Promise.reject(error)
        })

    return login
}
/**
 * 退出当前登录
 * @link http://10.20.5.146:9010/swagger-ui.html
 */
async function loginOut() {
    let loginOut = await util.ajax
        .get('/authorize/login-out')
        .then(res => {
            return res
        })
        .catch(error => {
            return Promise.reject(error)
        })

    return loginOut
}

export default {
    login,
    loginOut
}
